<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2019/12/10
  Time: 19:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<jsp:include page="../inc.jsp" />
<html>
<head>
    <title>学生信息主页</title>
    <script type="text/javascript">
        var list;
        function doPages(page){
            var count=10;
            var start =(page-1)*10;
            var end = start+count;
            // $.each(r,function(i,stu)
            for(var i =start;i<end;i++){
                var stu=list[i];
                var str = '<tr>' +
                    '<td><input type="checkbox"></td>' +
                    '<td>'+stu.name+'</td>' +
                    '<td>'+stu.sex+'</td>' +
                    '<td>'+stu.age+'</td>' +
                    '<td>'+stu.birthday+'</td>' +
                    '<td>'+stu.address+'</td>' +
                    '</tr>';
                $("#ctbody").append(str);
            }
        }

        function showPages(){
            $('#pages').twbsPagination({
                totalPages:10,
                visiblePages:5,
                first:'首页',
                last:'尾页',
                prev:'上一页',
                next:'下一页',
                onPageClick:function(event,page){
                    $("#ctbody").empty();
                    doPages(1);
                }
            });
        }
        $(function(){
            getData();
            showPages();
    })
        function getData(){
            $.ajax({
               type:"POST",
                url:"${ctx}/sc/find",
                async:false,
                dataType:"json",
                success:function(r){
                    list=r;

                                     }
                     })
    }
    </script>
</head>
<body>
    <div class="container">
        <div class="alert alert-success">
            <a class="close" href="#" data-dismiss="alert">&times;</a>
            <strong>这里显示学生的所有信息</strong>
        </div>
    </div>
    <div>
        <table class="table table-hover table-striped">
            <thead>
                <tr>
                    <th><input type="checkbox"></th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>出生日期</th>
                    <th>学号</th>
                    <th>身高</th>
                </tr>
            </thead>
            <tbody id="ctbody">
<%--                <tr>--%>
<%--                    <th><input type="checkbox"></th>--%>
<%--                    <th>yjt</th>--%>
<%--                    <th>男</th>--%>
<%--                    <th>2019-10-1</th>--%>
<%--                    <th>2019</th>--%>
<%--                    <th>190</th>--%>
<%--                </tr>--%>
            </tbody>
        </table>
        <ul id="pages" class="pagination-sm"></ul>
    </div>
</body>
</html>
